//! Package for the Object
package image;

import process.*;

/*! Az objektumk osztalya */
public class PhysiObject {

	private double posX;
	private double posY;
	private long timestamp;
	private double vX;
	private double vY;
	private double aX;
	private double aY;
	private KalmanFilter yFilter;
	private KalmanFilter xFilter;

	// ! Konstruktor
	/*
	 * ! \param message string
	 */
	public PhysiObject(double sigmaM, double sigmaW) {
		posX = 0;
		posY = 0;
		vX = 0;
		vY = 0;
		aX = 0;
		aY = 0;
		yFilter = new KalmanFilter(sigmaM, sigmaW);
		xFilter = new KalmanFilter(sigmaM, sigmaW);
	}

	// ! adattagokat aktualizalo fuggveny
	/*
	 * ! \param int img OwnImae class \param int long aktualis ido
	 */
	public void actualize(OwnImage img) throws ImageErrorException {
		int[] pos = ProcIm.getPos(img.Data);
		double t = img.timestamp - timestamp/(double)1000;

		double[] res = xFilter.filter(t, pos[0]);
		posX = res[0];
		vX = res[1];
		aX = res[2];

		res = yFilter.filter(t, pos[1]);
		posY = res[0];
		vY = res[1];
		aY = res[2];
		timestamp = img.timestamp;
	}

	// ! PosX visszateritese
	/*
	 * ! \return int
	 */
	public double getPosX() {
		return posX;
	}

	// ! Posy visszateritese
	/*
	 * ! \return int
	 */
	public double getPosY() {
		return posY;
	}

	// ! sebesseg visszateritese
	/*
	 * ! \return double
	 */
	public double getVelocity() {
		return Math.sqrt(vX * vX + vY * vY);
	}

	// ! gyorsulas visszateritese
	/*
	 * ! \return double
	 */
	public double getAcceleration() {
		return Math.sqrt(aX * aX + aY * aY);
	}

	public double[] getData() {
		double[] result = new double[5];
		result[0] = timestamp / (double) 1000;
		result[1] = posX;
		result[2] = posY;
		result[3] = getVelocity();
		result[4] = getAcceleration();
		return result;
	}
}
